package com.ys.controller;

import com.github.pagehelper.PageHelper;
import com.ys.mapper.BumenMapper;
import com.ys.pojo.Membertype;
import com.ys.pojo.User;
import com.ys.service.MembertypeService;
import com.ys.service.UserService;
import com.ys.vo.PageVo;
import com.ys.vo.ResultVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class UserContorller {
    @RequestMapping("/kuhu/kuhu")
    public String kuhu(){
        return "/kuhu/kuhu";
    }
    @RequestMapping("/kuhu/kuhuTypess")
    public String kuhuTypess(){
        return "/kuhu/kuhuTypess";
    }

    @Resource
    private UserService userService;
    @Resource
    private MembertypeService membertypeService;


    /**
     * 条件分页查询查询所有的客户
     * @param name
     * @param shoujihao
     * @param pageSize
     * @param pageNo
     * @return
     */
    @RequestMapping("/kuhu/select")
    @ResponseBody
    public ResultVo select(String name,String shoujihao,String pageSize,String pageNo,String yaodian){
        ResultVo resultVo = new ResultVo();
        PageHelper.startPage(Integer.parseInt(pageNo),Integer.parseInt(pageSize));
        resultVo.setObj(new PageVo(userService.findByLeiXingAndShoujihao(name,shoujihao,yaodian)));
        return resultVo;
    }

    /**
     * 用户的类型
     * @return
     */
    @RequestMapping("/kuhu/selecttype")
    @ResponseBody
    public ResultVo selecttype(){
        ResultVo resultVo = new ResultVo();
        resultVo.setObj(membertypeService.select());
        return resultVo;
    }







    @RequestMapping(value = "/kuhu/insert", produces = "html/text;charset=utf-8")
    @ResponseBody
    public ResultVo insert(@RequestBody User user){
        ResultVo resultVo = new ResultVo();
        if(userService.addsinsert(user)){
            resultVo.setMsg("添加成功!");
        }else {
            resultVo.setMsg("添加失败!");
        }
        return resultVo;
    }

    @RequestMapping(value = "/kuhu/update", produces = "html/text;charset=utf-8")
    @ResponseBody
    public ResultVo update(@RequestBody User user){
        System.out.println(user.getUserTypeid()+"update------------");
        ResultVo resultVo = new ResultVo();
        if(userService.updsupdate(user)){
            resultVo.setMsg("修改成功!");
        }else {
            resultVo.setMsg("修改失败!");
        }
        return resultVo;
    }

    @RequestMapping(value = "/kuhu/insertType", produces = "html/text;charset=utf-8")
    @ResponseBody
    public ResultVo insertType(@RequestBody Membertype membertype){
        ResultVo resultVo = new ResultVo();
        if(membertypeService.asddsinsert(membertype)){
            resultVo.setMsg("添加成功!");
        }else {
            resultVo.setMsg("添加失败!");
        }
        return resultVo;
    }

    @RequestMapping(value = "/kuhu/kuhuType", produces = "html/text;charset=utf-8")
    @ResponseBody
    public ResultVo kuhuType(@RequestBody Membertype membertype){
        ResultVo resultVo = new ResultVo();
        if(membertypeService.uspdsupdate(membertype)){
            resultVo.setMsg("修改成功!");
        }else {
            resultVo.setMsg("修改失败!");
        }
        return resultVo;
    }



}
